/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Receipt.java
 *
 * Created on 2011-mar-10, 08:08:22
 */

package imat;

import javax.swing.JLabel;
import javax.swing.JPanel;
import se.chalmers.ait.dat215.project.Order;
import se.chalmers.ait.dat215.project.ShoppingItem;

public class Receipt extends javax.swing.JPanel {

    //private static int ordernumber;

    /** Creates new form Receipt */
    public Receipt() {
        initComponents();
    }

    public void addReceiptRow(ShoppingItem item)
    {
       ReceiptRow row = new ReceiptRow();
       row.setReceiptRowAmountLabel(item.getAmount());
       row.setReceiptRowNameLabel(item.getProduct());
       row.setReceiptRowPriceLabel(item.getTotal());
       receiptRowPanel.add(row);
       receiptRowPanel.repaint();
       receiptRowPanel.revalidate();
    }

    public void setReceiptDate(Order order)
    {
        int year = order.getDate().getYear()+1900;
        int month= order.getDate().getMonth()+1;
        int day= order.getDate().getDay()+6;
        dateLabel.setText("Datum: "+year+"-"+month+"-"+day);
    }

    public void setReceiptPriceLabel(double price) {
        receiptPriceLabel.setText("Summa: "+price+"kr");
    }

    public JPanel getReceiptRowPanel() {
        return receiptRowPanel;
    }

        public void setDateLabel(String text)
    {
        dateLabel.setText(text);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dateLabel = new javax.swing.JLabel();
        receiptScrollPane = new javax.swing.JScrollPane();
        receiptRowPanel = new javax.swing.JPanel();
        receiptPriceLabel = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(Receipt.class);
        dateLabel.setFont(resourceMap.getFont("dateLabel.font")); // NOI18N
        dateLabel.setText(resourceMap.getString("dateLabel.text")); // NOI18N
        dateLabel.setName("dateLabel"); // NOI18N

        receiptScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        receiptScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        receiptScrollPane.setName("receiptScrollPane"); // NOI18N

        receiptRowPanel.setName("receiptRowPanel"); // NOI18N
        receiptRowPanel.setLayout(new javax.swing.BoxLayout(receiptRowPanel, javax.swing.BoxLayout.Y_AXIS));
        receiptScrollPane.setViewportView(receiptRowPanel);

        receiptPriceLabel.setFont(resourceMap.getFont("receiptPriceLabel.font")); // NOI18N
        receiptPriceLabel.setText(resourceMap.getString("receiptPriceLabel.text")); // NOI18N
        receiptPriceLabel.setName("receiptPriceLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(receiptPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
            .addComponent(receiptScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
            .addComponent(dateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(dateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(receiptScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(receiptPriceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel dateLabel;
    private javax.swing.JLabel receiptPriceLabel;
    private javax.swing.JPanel receiptRowPanel;
    private javax.swing.JScrollPane receiptScrollPane;
    // End of variables declaration//GEN-END:variables

}
